package org.bluesky.controller;

import org.bluesky.framework.ResponseResult;
import org.bluesky.framework.dto.UpdateUserDto;
import org.bluesky.framework.dto.UserDto;
import org.bluesky.framework.entity.User;
import org.bluesky.framework.service.UserService;
import org.bluesky.framework.vo.PageVo;
import org.bluesky.framework.vo.UserRoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("system/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public ResponseResult list(UserDto userDto, Integer pageNum, Integer pageSize){
        PageVo pageVo = userService.getArticleList(userDto,pageNum,pageSize);
        return ResponseResult.okResult(pageVo);
    }

    @PostMapping
    public ResponseResult addUser(@RequestBody UserRoleVo userRoleVo){
        return userService.addUser(userRoleVo);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteUser(@PathVariable("id")Long id){
        userService.removeById(id);
        return ResponseResult.okResult();
    }

    @GetMapping("/{id}")
    public ResponseResult getUser(@PathVariable("id")Long id){
        return userService.getUser(id);
    }

    @PutMapping("")
    public ResponseResult updateUser(@RequestBody UpdateUserDto userDto){
        return userService.updateUser(userDto);
    }
}
